#! /usr/bin/env python
# -*- coding:utf-8 -*-
#author:无涯

from base.method import ApiHttp
from utils.operationYaml import  getUrl
from utils.operationJson import readJson
from common.public import *

obj=ApiHttp()

def addProduct(headers):
	r=obj.post(
		url=getUrl()+"/interface/product/",
		json=readJson()['product'],
		headers=headers)
	wtiteID(fileName='productID',content=r.json()['id'])
	return r

def soProduct(headers,params=""):
	r=obj.get(
		url=getUrl()+"/interface/products",
		params={'name':params},
		headers=headers)
	return r

def setProduct(headers,data=None):
	dict1=readJson()[data]
	dict1['id']=int(readID(fileName='productID'))
	r=obj.put(url=getUrl()+"/interface/product/{productID}/".format(
		productID=readID(fileName='productID')),
	          json=dict1,
	          headers=headers)
	return r


def delProduct(headers):
	r=obj.delete(
		url=getUrl()+"/interface/product/{productID}/".format(
			productID=readID(fileName='productID')),
		headers=headers)
	return r